import optionsx from '@/Echarts/柱状图'
import * as echarts from 'echarts'
let options = JSON.parse(JSON.stringify(optionsx))
// const { echarts } = window

export default (element, data) => {
  const old = echarts.getInstanceByDom(element)
  if (old) old.dispose()
  const chart = echarts.init(element, 'theme')
  // eslint-disable-next-line no-unused-vars
  if (data.xAxis) {

    options = {
      tooltip: {
        trigger: 'axis',
        axisPointer: {
          type: 'shadow'
        },
      },
      legend: {
        show: true,
        textStyle:{fontSize:12},
      },
      grid: {
        left: '10%',
        right: '4%',
        top: '7%',
        bottom: '10%',
        containLabel: false
      },
      xAxis: [
        {
          type: 'category',
          data: data.xAxis
        }
      ],
      yAxis: [
        {
          type: 'value'
        }
      ],
      series: [
        {
          name: '项目区产值',
          type: 'bar',
          stack: 'Ad',
          emphasis: {
            focus: 'series'
          },

          data: data.data1
        },
        {
          name: '全省产值',
          type: 'bar',
          stack: 'Ad',
          emphasis: {
            focus: 'series'
          },

          data: data.data2
        },
        // {
        //   name: '项目区产量',
        //   type: 'line',
        //   areaStyle:null,
        //   data: data.data3
        // },
        // {
        //   name: '全省产量',
        //   type: 'line',
        //   areaStyle:null,
        //   data: data.data4
        // },
      ]
    };
  }
  options.yAxis.name = ''
  chart.setOption(options)
  return chart
}
